package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.ShippingAddressEntity;
import com.zw.yzk.kabu.model.ShippingAddressModel;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/12.
 */

public class ShippingAddressMapper {

    @Inject
    public ShippingAddressMapper() {

    }

    public ShippingAddressModel transfer(ShippingAddressEntity.Address address) {
        ShippingAddressModel model = new ShippingAddressModel();
        model.setName(address.receiverName);
        model.setAddress(address.address);
        model.setPhone(address.receiverPhone);
        model.setId(address.id);
        model.setSelected(address.isDefault == 1);

        return model;
    }

    public List<ShippingAddressModel> transfer(ShippingAddressEntity entity) {
        List<ShippingAddressModel> models = new ArrayList<>();
        if(entity.result.addressList == null || entity.result.addressList.isEmpty()) {
            return models;
        }
        for(ShippingAddressEntity.Address address : entity.result.addressList) {
            models.add(transfer(address));
        }
        return models;
    }
}
